<?php
/**
* Django's templating engine (partial) PHP implementation.
* provides some template tags support
* @link http://djangoproject.com
* this file is from a webappkit package (kit)
* @link http://webappkit.net
* @package djtpl
* @author J.Ducastel <nospam0@ducastel.name>
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*/

/**
* 'firstof' tag. Renders first of vars which is not null/false
* <code>{% firstof var1 var2 var3 %}</code>
*/
class djtplTagNode_firstOf extends djtplTagNode {

    /**
    * builds itself from tokens
    * @param djangoTplToken &$selfToken
    * @param array &$nextTokens djangoTplToken
    * @access public
    * @return bool
    */
    function buildFromTokens(&$selfToken) {
        $def=$selfToken->tagdef;
        $this->vars=explode(' ',$def);
        return true;
    }/**/

    /**
    * is the node atomic (has no children)
    * @access public
    * @return bool
    */
    function isAtomic() {
        return true;
    }/**/
    
    /**
    * renders as string
    * @param djangoTplContext &$context
    * @access public
    * @return string
    */
    function render(&$context) {
        foreach ($this->vars as $var) {
            if ($value=$context->getPath($var))
                return strval($value);
        }
        return '';
    }/**/
    
    var $tagname='firstof';
}
?>
